<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__ROOT__/layui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="__ROOT__/layui/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

<!--        <fieldset class="table-search-fieldset">-->
<!--            <legend>搜索信息</legend>-->
<!--            <div style="margin: 10px 10px 10px 10px">-->
<!--                <form class="layui-form layui-form-pane" action="">-->
<!--                    <div class="layui-form-item">-->
<!--                        <div class="layui-inline">-->
<!--                            <label class="layui-form-label">项目编号</label>-->
<!--                            <div class="layui-input-inline">-->
<!--                                <input type="text" name="username" autocomplete="off" class="layui-input">-->
<!--                            </div>-->
<!--                        </div>-->
<!--                        <div class="layui-inline">-->
<!--                            <label class="layui-form-label">项目关键词</label>-->
<!--                            <div class="layui-input-inline">-->
<!--                                <input type="text" name="sex" autocomplete="off" class="layui-input">-->
<!--                            </div>-->
<!--                        </div>-->
<!--                        <div class="layui-inline">-->
<!--                            <label class="layui-form-label">技术关键词</label>-->
<!--                            <div class="layui-input-inline">-->
<!--                                <input type="text" name="city" autocomplete="off" class="layui-input">-->
<!--                            </div>-->
<!--                        </div>-->
<!--                        <div class="layui-inline">-->
<!--                            <label class="layui-form-label">用户旺旺</label>-->
<!--                            <div class="layui-input-inline">-->
<!--                                <input type="text" name="classify" autocomplete="off" class="layui-input">-->
<!--                            </div>-->
<!--                        </div>-->
<!--                        <div class="layui-inline">-->
<!--                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                </form>-->
<!--            </div>-->
<!--        </fieldset>-->

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加订单 </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            {{#  if(d.user_id == null){ }}
            <a class="layui-btn layui-btn-green layui-btn-xs data-count-edit" lay-event="up_add">上传文档</a>
            {{#  } else { }}

            {{#  } }}
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">项目初审</a>
            <a class="layui-btn layui-btn-xs layui-btn-warm data-count-user "  lay-event="user">用户信息</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
<script src="__ROOT__/layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/bang/public/index.php/index/order/get_order_check',
            toolbar: '#toolbarDemo'
            ,defaultToolbar: [{ //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
            title: '提示'
            ,layEvent: 'LAYTABLE_TIPS'
            ,icon: 'layui-icon-tips'
        }],
            cellMinWidth: 80,
            cols: [[
                {field: 'num',  title: '编号', sort: true , fixed: 'left',},
                {field: 'name',  title: '项目名称'},
                {field: 'language',  title: '编程语言'},
                {field: 'platform',  title: '实现平台'},
                {field: 'industry', title: '应用行业'},
                {field: 'field',  title: '技术领域'},
                {field: 'min',  title: '最小预算'},
                {field: 'max',  title: '最大预算'},
                {field: 'state',  title: '项目状态'},
                {field: 'datetime', title: '期望交付时间', sort: true},
                {title: '操作', width: 250,  toolbar: '#currentTableBar', align: "center" ,fixed: 'right'}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 30,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加订单',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['80%', '80%'],
                    content: '/bang/public/index.php/index/order/add',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var mdata = obj.data;

            if (obj.event === 'edit') {

                var index = layer.open({
                    title: '项目初审，补充完整订单信息',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['70%', '80%'],
                    content: '/bang/public/index.php/index/order/check_edit?id='+mdata.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的要删除吗', function (index) {
                    var url = "{:url('order/check_del')}";
                    var data={'num':mdata.num};
                    var success = "{:url('order/check')}";
                    //    执行异步请求 ，$.post
                    $.post(url,data,function(result){
                        if(result.status ==0){
                            layer.open({
                                content:result.message,
                                icon:2,
                                title : '错误提示'
                            });

                        }
                        if(result.status ==1){
                            layer.open({
                                content : result.message,
                                icon : 1,
                                yes : function(){
                                    location.href=success;
                                }
                            });

                        }
                    },'JSON');
                    return false;

                });
            }
            else if (obj.event === 'user') {
                layer.tips('电话:'+mdata.user_phone+'<br>'+'qq:'+mdata.user_qq+'<br>', this, {
                    tips: [1, '#3595CC'],
                    time: 4000
                });
            }
            else if (obj.event === 'up_add') {
                var index = layer.open({
                    title: '上传该项目相关文档',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['70%', '80%'],
                    content: '/bang/public/index.php/index/order/up_file?id='+mdata.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }
        });

    });
</script>

</body>
</html>